home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio.more / old / PascalToCPlus next >
Text File  |  1996-07-05  |  9KB  |  259 lines

  1. #Select the following scripts and execute on your pascal file
  2.  
  3. # Token substitution scripts.
  4. set CaseSensitive 1
  5. set Exit 0
  6. find Δ1
  7. replace -c ∞ /'{'/ '/*' {Target}
  8. find Δ1
  9. replace -c ∞ /'(*'/ '/*' {Target}
  10. find Δ1
  11. replace -c ∞ /'}'/ '*/' {Target}
  12. find Δ1
  13. replace -c ∞ /'*)'/ '*/' {Target}
  14. find Δ1
  15. replace -c ∞ /'BEGIN'/ '{' {Target}
  16. find Δ1
  17. replace -c ∞ /END[¬C]/ '}' {Target}
  18. find Δ1
  19. replace -c ∞ /([ ∂t∂n]+)®1'='([ ∂t∂n]+)®2/ ®1'=='®2 {Target}
  20. find Δ1
  21. replace -c ∞ /([ ∂t∂n]+)®1'&'([ ∂t∂n]+)®2/ ®1'&&'®2 {Target}
  22. find Δ1
  23. replace -c ∞ /([ ∂t∂n]+)®1'AND'([ ∂t∂n]+)®2/ ®1'&&'®2 {Target}
  24. find Δ1
  25. replace -c ∞ /([ ∂t∂n]+)®1'|'([ ∂t∂n]+)®2/ ®1'||'®2 {Target}
  26. find Δ1
  27. replace -c ∞ /([ ∂t∂n]+)®1'OR'([ ∂t∂n]+)®2/ ®1'||'®2 {Target}
  28. find Δ1
  29. replace -c ∞ /'<>'/ '!=' {Target}
  30. find Δ1
  31. replace -c ∞ /'NOT '/ '!' {Target}
  32. find Δ1
  33. replace -c ∞ /':='/ '=' {Target}
  34. find Δ1
  35. replace -c ∞ /'@'/ '&' {Target}
  36. find Δ1
  37. # Change all ifs except macros
  38. replace -c ∞ /'IF'[ ∂t]+/ 'if (' {Target}        #changed APW 7/8/91 to handle IF (T) or (F) THEN
  39. find Δ1
  40. replace -c ∞ /[ ∂t]+'THEN'/ ')' {Target}
  41. find Δ1
  42. replace -c ∞ /'ELSE'/ 'else' {Target}
  43. find Δ1
  44. replace -c ∞ /'WHILE'/ 'while (' {Target}
  45. find Δ1
  46. replace -c ∞ /[ ∂t]+'DO'[ ∂t∂n]+/ ')' {Target}
  47. find Δ1
  48. replace -c ∞ /'REPEAT'/ 'do {' {Target}
  49. find Δ1
  50.  
  51. # replace "UNTIL x < y;" with "while (!(x < y));"  #changed APW 7/8/91 -- added !()
  52. replace -c ∞ /'UNTIL '([(a-zA-Z0-9)+∂/<>!=&|^* .-∂t]+)®1/ '} while (!(®1))' {Target}
  53. find Δ1
  54.  
  55. # First change to 'FUNCTION' to 'pascal'
  56. replace -c ∞ /'FUNCTION'/ 'pascal' {Target}
  57. find Δ1
  58.  
  59. # Then swap the order of functions without parameters and their return type
  60. replace -c ∞ /'pascal'[ ∂t]+([a-zA-Z0-9%_.]+)®1':'([ ∂t]+)([a-zA-Z0-9]+)®2';'/ 'pascal '®2' '®1'(void)'
  61. find Δ1
  62.  
  63. # Same for functions with parameters (Can't handle function parameters)
  64. replace -c ∞ /'pascal'[ ∂t]+([a-zA-Z0-9_%.]+[ ∂t]*'('[a-zA-Z0-9$, :;∂t∂n]+)®1'):'[ ∂t∂n]+([a-zA-Z0-9]+)®2';'/ 'pascal '®2' '®1');'    #Leave ; for scripts further down
  65. find Δ1
  66.  
  67. # Now replace PROCEDURE with pascal and a type of void
  68. replace -c ∞ /'PROCEDURE'/ 'pascal void' {Target}
  69. find Δ1
  70.  
  71. # Give procedures with no parameters a parameter of void
  72. replace -c ∞ /'pascal void'[ ∂t]+([a-zA-Z0-9%_.]+)®1';'/ 'pascal void '®1'(void)'
  73. find Δ1
  74.  
  75. # Finally, if it is a class function, change from tobject.foo to tobject::foo
  76. replace -c ∞ /'pascal'[ ∂t]+([ a-zA-Z0-9%_]+)®1./ 'pascal '®1'::' {Target}
  77.  
  78. find Δ1
  79. replace -c ∞ /'OVERRIDE;'/ '/* override */' {Target}
  80. find Δ1
  81. replace -c ∞ /INTEGER/ 'short' {Target}
  82. find Δ1
  83. replace -c ∞ /LONGINT/ 'long' {Target}
  84. find Δ1
  85. replace -c ∞ /BOOLEAN/ 'Boolean' {Target}
  86. find Δ1
  87. replace -c ∞ /CHAR/ 'char' {Target}
  88. find Δ1
  89. replace -c ∞ /[Oo][Rr][Dd]4[ ∂t]*'('([a-zA-Z0-9*∂/&+∂-∂[∂]()∂']+)®1')'/ '((long)'®1')' {Target}
  90. find Δ1
  91. replace -c ∞ /[Cc][Hh][Rr][ ∂t]*'('([a-zA-Z0-9*∂/∂%$&+∂-∂[∂]()∂' ]+)®1')'([;,)])®2/ '((char)('®1'))'®2 {Target}
  92. find Δ1
  93. replace -c ∞ /'long'[ ∂t]*'('([a-zA-Z0-9*&+∂-∂[∂]()∂' ]+)®1')'/ '((long)'®1')' {Target}
  94. find Δ1
  95. replace -c ∞ /'DIV'/ '/' {Target}
  96. find Δ1
  97. replace -c ∞ /'MOD'/ '%' {Target}
  98. find Δ1
  99. replace -c ∞ /'SELF'/ 'this' {Target}
  100. find Δ1
  101. replace -c ∞ /'^.'/ '->' {Target}
  102. find Δ1
  103.  
  104. # replace HInteger(pSuperClassTable)^ with (*HInteger(pSuperClassTable))
  105. replace -c ∞ /([a-zA-Z0-9]+)®1'('([a-zA-Z0-9 ∂t+-*∂/()]+)®2')^'/ '(*'®1'('®2'))' {Target}
  106. find Δ1
  107.  
  108. # replace HInteger(pSuperClassTable)^^ with (**HInteger(pSuperClassTable))
  109. replace -c ∞ /([a-zA-Z0-9]+)®1'('([a-zA-Z0-9 ∂t+-*∂/()]+)®2')^^'/ '(**'®1'('®2'))' {Target}
  110. find Δ1
  111.  
  112. # replace pSuperClassTable^[index] with (*pSuperClassTable)[index] !Note [] and () are higher than *
  113. replace -c ∞ /([a-zA-Z0-9]+)®1'^'/ '(*'®1')' {Target}
  114. find Δ1
  115.  
  116. # replace pSuperClassTable^^ with **pSuperClassTable
  117. replace -c ∞ /([a-zA-Z0-9]+)®1'^^'/ '(**'®1')' {Target}
  118.  
  119. find Δ1
  120. replace -c ∞ /'INHERITED'[ ∂t]+/ 'inherited::' {Target}
  121. find Δ1
  122. replace -c ∞ /'EXIT'/ 'exit' {Target}
  123. find Δ1
  124. replace -c ∞ /'LENGTH'/ 'strlen' {Target}
  125. find Δ1
  126. replace -c ∞ /'SIZEOF'/ 'sizeof' {Target}
  127. find Δ1
  128. replace -c ∞ /([¬a-zA-Z0-9_]+)®1'NIL'([¬a-zA-Z0-9_]+)®2/ ®1'NULL'®2 {Target}
  129. find Δ1
  130.  
  131. # replace "BSR(x + y, 2)" with "((x + y) >> 2)"
  132. replace -c ∞ /'BSR('([(a-zA-Z0-9)+∂/* .∂->∂t∂[∂]]+)®1[ ∂t]*','([ ∂ta-zA-Z0-9$]+)®2[ ∂t)]/ '(('®1') >>'®2')' {Target}
  133. find Δ1
  134.  
  135. # replace "BSL(x + y, 2)" with "((x + y) << 2)"
  136. replace -c ∞ /'BSL('([(a-zA-Z0-9)+∂/* .∂->∂t∂[∂]]+)®1[ ∂t]*','([ ∂ta-zA-Z0-9$]+)®2[ ∂t)]/ '(('®1') <<'®2')' {Target}
  137. find Δ1
  138.  
  139. # replace "BAND(x + y, 2)" with "((x + y) & 2)"
  140. replace -c ∞ /'BAND('([(a-zA-Z0-9)+∂/* .∂->∂t∂[∂]]+)®1[ ∂t]*','([ ∂ta-zA-Z0-9$]+)®2[ ∂t)]/ '(('®1') &'®2')' {Target}
  141. find Δ1
  142.  
  143. # replace "BOR(x + y, 2)" with "((x + y) | 2)"
  144. replace -c ∞ /'BOR('([(a-zA-Z0-9)+∂/* .∂->∂t∂[∂]]+)®1[ ∂t]*','([ ∂ta-zA-Z0-9$]+)®2[ ∂t)]/ '(('®1') |'®2')' {Target}
  145. find Δ1
  146.  
  147. # replace "BTST(x + y, 2)" with "((x + y) & (0x1 << 2))"
  148. replace -c ∞ /'BTST('([(a-zA-Z0-9)+∂/* .∂->∂t∂[∂]]+)®1[ ∂t]*','([ ∂ta-zA-Z0-9$]+)®2[ ∂t)]/ '(('®1') & (0x1 <<'®2'))' {Target}
  149. find Δ1
  150.  
  151. # replace "BCLR(x + y, 2)" with "((x + y) & ((0x1 << 2) ^ ~0))"
  152. replace -c ∞ /'BCLR('([(a-zA-Z0-9)+∂/* .∂->∂t∂[∂]]+)®1[ ∂t]*','([ ∂ta-zA-Z0-9$]+)®2[ ∂t)]/ '(('®1') & ((0x1 <<'®2') ^ ~0))' {Target}
  153. find Δ1
  154.  
  155. #replace "/* $IFC qDebug */" ({ has been replaced above with /*) with "#if qDebug"
  156. replace -c ∞ /[ ∂t]*'/*'[ ∂t]*'$'[Ii][Ff][Cc][ ∂t]([a-zA-Z0-9]+)®1[ ∂t]*'*/'/ '#if '®1 {Target}
  157. find Δ1
  158.  
  159. #replace "/* $IFC !qDebug */"  with "#if !qDebug"
  160. replace -c ∞ /[ ∂t]*'/*'[ ∂t]*'$'[Ii][Ff][Cc][ ∂t]'!'([a-zA-Z0-9]+)®1[ ∂t]*'*/'/ '#if !'®1 {Target}
  161. find Δ1
  162.  
  163. #replace "/* $EndC */"  with "#endif"
  164. replace -c ∞ /[ ∂t]*'/*'[ ∂t]*'$'[eE][nN][dD][cC][ ∂ta-zA-Z0-9]*'*/'/ '#endif' {Target}
  165. find Δ1
  166.  
  167. #replace "/* $ElseC */"  with "#else"
  168. replace -c ∞ /[ ∂t]*'/*'[ ∂t]*'$'[eE][lL][sS][eE][cC][ ∂ta-zA-Z0-9]*'*/'/ '#else' {Target}
  169. find Δ1
  170.  
  171. #replace "/* $S MADebug */"  with "#pragma segment MADebug"
  172. replace -c ∞ /[ ∂t]*'/*'[ ∂t]*'$'[sS][ ∂t]([a-zA-Z0-9%_]+)®1[ ∂t]*'*/'/ '#pragma segment '®1 {Target}
  173. find Δ1
  174.  
  175. #replace /* comment */ at the end of the line with // comment
  176. replace -c ∞ /([ ∂t]*)®1'/*'([- ∂ta-zA-Z0-9?,<>.…∂/∂\:;∂"∂'∂[∂]{}+=_!@#$%^&*()∂`~|]+)®2'*/'∞/ ®1'//'®2 {Target}
  177. find Δ1
  178.  
  179. #replace $number (hex number) with 0xnumber
  180. replace -c ∞ /([ ∂t(]+)®1'$'([0-9A-F]+)®2/ ®1'0x'®2 {Target}
  181. find Δ1
  182.  
  183. # replaces gApplication.foo() with gApplication->foo()
  184. replace -c ∞ /([a-zA-Z0-9*()]+)®1.([a-zA-Z0-9]+)®2'('/ ®1'->'®2'(' {Target}
  185. find Δ1
  186.  
  187. # Parameters replaces newColor: RGBColor); with RGBColor newColor)
  188. replace -c ∞ /([ ∂t(]*)®1([a-zA-Z0-9_%, ]+)®2':'[ ∂t]+([a-zA-Z0-9_%]+)®3[ ∂t]*');'/ ®1®3' '®2')' {Target}
  189. find Δ1
  190.  
  191. # Parameters replaces ; newColor: RGBColor; with ; RGBColor    newColor,
  192. replace -c ∞ /(';'[ ∂t]*)®1([a-zA-Z0-9_% ,]+)®2':'[ ∂t]+([a-zA-Z0-9_%]+)®3';'/ ®1®3' '®2',' {Target} # Can't handle more than one middle parameter.
  193. find Δ1
  194.  
  195. # Parameters replaces (newColor: RGBColor; with (RGBColor    newColor,
  196. replace -c ∞ /('('[ ∂t]*)®1([a-zA-Z0-9_% ,]+)®2':'[ ∂t]+([a-zA-Z0-9_%]+)®3';'/ ®1®3' '®2',' {Target}
  197. find Δ1
  198.  
  199. # Variables replaces newColor: RGBColor; with RGBColor            newColor;
  200. replace -c ∞ /•([ ∂t]+)®1([a-zA-Z0-9_% ,]+)®2':'[ ∂t]+([a-zA-Z0-9_%]+)®3';'/ ®1®3∂t∂t®2';' {Target}
  201. find Δ1
  202.  
  203. # Variables replaces labels: ARRAY [VHSelect] OF TStaticText; with TStaticText labels[VHSelect];
  204. replace -c ∞ /•([ ∂t]+)®1([a-zA-Z0-9_%]+)®2':'[ ∂t]+'ARRAY'[ ∂t]*'['([a-zA-Z0-9_%]+)®3']'[ ∂t]+'OF'[ ∂t]+([a-zA-Z0-9_%]+)®4';'/ ®1®4∂t®2'['®3'];' {Target}
  205. find Δ1
  206.  
  207. # Add () to the end of function calls without parameters:    FramRect; -> FrameRect();
  208. replace -c ∞ /•([ ∂t]+)®1([a-zA-Z0-9_%]+)®2';'/ ®1®2'();' {Target}
  209. find Δ1
  210.  
  211. # Add () to the end of inherited function calls without parameters:    inherited::FramRect; -> inherited::FrameRect();
  212. replace -c ∞ /•([ ∂t]+)®1'inherited::'([a-zA-Z0-9_%]+)®2';'/ ®1'inherited::'®2'();' {Target}
  213. find Δ1
  214.  
  215. # change aSomething.fAnotherThing to fSomething->fAnotherThing (Assume its a field)
  216. replace -c ∞ /([a-z])®1([a-zA-Z0-9_%]+)®2'.f'([A-Z])®3([a-zA-Z0-9_%]+)®4/ ®1®2'->f'®3®4 {Target}
  217. find Δ1
  218.  
  219. # change aSomething.AnotherProc to aSomething->AnotherProc() (Assume its a field)
  220. replace -c ∞ /([a-z])®1([a-zA-Z0-9_%]+)®2'.'([A-Z])®3([a-zA-Z0-9_%]+)®4[ ∂t]*([;,∂)])®5/ ®1®2'->'®3®4'()'®5 {Target}
  221. find Δ1
  222.  
  223. # change CASE junk OF to switch (junk) {
  224. replace -c ∞ /•([ ∂t]*)®1'CASE'[ ∂t]+([a-zA-Z0-9_%]+)®2[ ∂t]+'OF'/ ®1'switch ('®2') {' {Target}
  225. find Δ1
  226.  
  227. # change         1: to        case 1: for switch statement
  228. replace -c ∞ /•([ ∂t]+)®1([a-zA-Z0-9_%]+)®2':'([ ∂t]*)®3∂n/ ®1'case '®2':'®3∂n {Target}
  229. find Δ1
  230.  
  231. # change OTHERWISE to default:
  232. replace -c ∞ /•([ ∂t]+)®1'OTHERWISE'/ ®1'default:' {Target}
  233. find Δ1
  234.  
  235. # replace DoToField(....) with obj->DoToField(....)
  236. replace -c ∞ /•([ ∂t]*)®1'DoToField(AtStr('∂'([a-zA-Z0-9_%.]+)®2∂''),'[ ∂t]*([a-zA-Z0-9_%&.]+)®3','[ ∂t]*([a-zA-Z0-9_%]+)®4/ ®1'obj->DoToField("'®2'", (Ptr)'®3', '®4 {Target}
  237. find Δ1
  238.  
  239. # replace member functions with new
  240. replace -c ∞ /([ ∂t]*)®1'if (MEMBER(TObject(NIL), T'([a-zA-Z0-9_%]+)®2')) ;'/ ®1'a'®2' = new T'®2';' {Target}
  241. find Δ1
  242.  
  243. # Move variables into block
  244. replace -c ∞ /•([ ∂t]+)®1'VAR'∂n([a-zA-Z0-9_%; ∂t∂n]+)®2'{'/ ®1'{'∂n®2 {Target}
  245. find Δ1
  246.  
  247. # Turn implementation uses into proper includes
  248. find •
  249. loop
  250.     break if {status}
  251.     find •
  252.     replace  /'USES'[ ∂t∂n]*([a-zA-Z0-9]+)®1','/ ∂n'#ifndef __'®1'__'∂n'#include <'®1'.h>'∂n'#endif'∂n'USES' {Target}
  253. end
  254. find •
  255. replace  /'USES'[ ∂t∂n]*([a-zA-Z0-9]+)®1';'/ ∂n'#ifndef __'®1'__'∂n'#include <'®1'.h>'∂n'#endif'∂n {Target}
  256.  
  257. set CaseSensitive 0
  258. set Exit 1
  259.